define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'reimbuse/index',
        export_url: 'reimbuse/export',
        detail_url: 'reimbuse/detail',
        reject_url: 'reimbuse/reject',
        through_url: 'reimbuse/through',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh','export'],
                cols: [[
                    {field: 'id', title: '编号', search: false, width: 100},
                    {field: 'true_name', title: '员工姓名'},
                    {field: 'amount', title: '报销金额', search: false},
                    {field: 'payment', title: '报销备注', search: false},
                    {field: 'status', search: 'select', selectList: ["已通过","被驳回"], title: '审核结果', templet: function (d) {
                            if (d.status == 0){
                                return '<div class="layui-table-cell" style="color: blue;">待审核</div>';
                            }else if (d.status == 1){
                                return '<div class="layui-table-cell" style="color: green;">已通过</div>';
                            }else{
                                return '<div class="layui-table-cell" style="color: red;">被驳回</div>';
                            }
                        }
                    },
                    {field: 'create_time', title: '申请时间', search: 'range'},
                    {
                        width: 180,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '详情',
                                url: init.detail_url,
                                method: 'open',
                                auth: 'detail',
                                class: 'layui-btn layui-btn-xs layui-btn',
                                extend: 'data-full="true"',
                            },{
                                text: '驳回',
                                url: init.reject_url,
                                method: 'open',
                                auth: 'reject',
                                class: 'layui-btn layui-btn-xs layui-btn-danger',
                                extend: 'data-width="660px" data-height="420px"'
                            },{
                                text: '通过',
                                title: '确定通过？',
                                url: init.through_url,
                                method: 'request',
                                auth: 'through',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                            }]
                        ]
                    }
                ]],
            });
            ea.listen();
        },
        index2: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'reimbuse/index2',
                },
                toolbar: ['refresh','export'],
                cols: [[
                    {field: 'id', title: '编号', hide: true, search: false, width: 100},
                    {field: 'true_name', title: '员工姓名'},
                    {field: 'amount', title: '报销金额', search: false},
                    {field: 'payment', title: '报销备注', search: false},
                    {field: 'status', search: 'select', selectList: ["已通过","被驳回"], title: '审核结果', templet: function (d) {
                            if (d.status == 0){
                                return '<div class="layui-table-cell" style="color: blue;">待审核</div>';
                            }else if (d.status == 1){
                                return '<div class="layui-table-cell" style="color: green;">已通过</div>';
                            }else{
                                return '<div class="layui-table-cell" style="color: red;">被驳回</div>';
                            }
                        }
                    },
                    {field: 'description', title: '审核备注', search: false},
                    {field: 'update_time', title: '审核时间', search: 'range'},
                    {
                        width: 180,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '详情',
                                url: init.detail_url,
                                method: 'open',
                                auth: 'detail',
                                class: 'layui-btn layui-btn-xs layui-btn',
                                extend: 'data-full="true"',
                            }]
                        ]
                    }
                ]],
            });
            ea.listen();
        },
        detail: function () {
            ea.listen();
        },
        reject: function () {
            ea.listen();
        }
    };
    return Controller;
});